﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Collections.Generic;
using Baosight.Platform.Core.UI.Controls;
using Baosight.ZNH.ZMCA.UI.Utils;
using Telerik.Windows.Controls.Charting;
using Telerik.Windows.Controls;
using Baosight.Platform.Core;
using Baosight.Platform.Core.ServiceModel;
using Baosight.ZNH.ZMCA.UI.Controls;
using System.Reflection;
using Baosight.ZNH.ZMCA.UI.Model;


namespace Baosight.ZNH.ZMCA.UI
{//综合分析中心页面，原煤产量柱状曲线图
    public partial class ZMCA72 : UserControl
    {
        public ZMCA72()
        {
            InitializeComponent();
            QueryInfo();
        }

        private void QueryInfo()
        {
            EIInfo eiInfo = new EIInfo();
            eiInfo.Set("service", "ZMCA03");
            eiInfo.Set("method", "queryProjectOutput");

            HttpServiceAgent agent = new HttpServiceAgent();
            agent.CallService(eiInfo, doQueryCompleted);
        }

        private void doQueryCompleted(object sender, DoWorkCompletedEventArgs e)
        {
            if (e.EIInfo.Status == -1)
            {
                Common.Alert(Common.MsgLoadDataError);
                return;
            }
            EIBlock result = e.EIInfo.GetBlock("result");
            InitTrendChart();
            TrendChart.ItemsSource = null;

            List<List<ChartData>> ItemsSource = new List<List<ChartData>>();
            List<ChartData> lstActual = new List<ChartData>();
            List<ChartData> lstPlan = new List<ChartData>();

            foreach (var item in result.Rows)
            {
                lstPlan.Add(new ChartData(Common.GetStringValue(item["fdProjectName"]),
                    Common.GetDecimalValue(item["fdPlanGrub"])));
                lstActual.Add(new ChartData(Common.GetStringValue(item["fdProjectName"]),
                    Common.GetDecimalValue(item["fdActualSum"])));
            }

            TrendChart.ItemsSource = ItemsSource;
        }

        public void InitTrendChart()
        {
            Common.ClearChart(TrendChart);
            //趋势图
            TrendChart.SeriesMappings.Clear();
            TrendChart.DefaultView.ChartTitle.Content = "本月采煤总量";
            TrendChart.DefaultSeriesDefinition.ShowItemToolTips = true;
            TrendChart.DefaultSeriesDefinition.LegendDisplayMode = LegendDisplayMode.DataPointLabel;
            TrendChart.DefaultView.ChartLegend.Header = "";

            TrendChart.DefaultView.ChartArea.AxisY.MajorGridLinesVisibility = Visibility.Visible;
            TrendChart.DefaultView.ChartArea.AxisY.MinorGridLinesVisibility = Visibility.Visible;
            TrendChart.DefaultView.ChartArea.AxisY.StripLinesVisibility = Visibility.Visible;

            SeriesMapping smBar = new SeriesMapping();
            BarSeriesDefinition totalBar = new BarSeriesDefinition();
            smBar.SeriesDefinition = totalBar;
            smBar.CollectionIndex = 0;
            smBar.LegendLabel = "原煤总量";
            smBar.SeriesDefinition.ShowItemLabels = false;
            smBar.SeriesDefinition.ShowItemToolTips = true;
            smBar.SeriesDefinition.ShowZeroValuesLabels = true;
            smBar.ItemMappings.Add(new ItemMapping("Project", DataPointMember.XCategory));
            smBar.ItemMappings.Add(new ItemMapping("DataValue", DataPointMember.YValue));
            smBar.SeriesDefinition.InteractivitySettings.HoverScope = InteractivityScope.Series;
            smBar.SeriesDefinition.InteractivitySettings.SelectionScope = InteractivityScope.Series;
            smBar.SeriesDefinition.InteractivitySettings.SelectionMode = ChartSelectionMode.Multiple;
            TrendChart.SeriesMappings.Add(smBar);
        }
    }
}
